I think that the role of David had been to reestablish the kingdom of God in Israel by protecting the lives of the chosen people of God the Father. There had been past sins committed by David. However, there had also been repentance shown by David to the extent that Yahweh had been pleased with him. Therefore, Yahweh had not wanted David to go away from the covenant which God had wanted to make with him. This implies that there is always a covenant of God which God wants to establish/form with every human being. However, it is up to the human being whether the human being makes 100% effort to believe in God and maintain the covenant or not.